<!DOCTYPE html>
<html lang="en">
<head>
    <meta content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="format-detection" content="email=no">
    <meta charset="UTF-8">
    <title>支付</title>
    <link rel="stylesheet" href="../css/base.css">
    <style>
        #slh{  
        	overflow: hidden;
            text-overflow:ellipsis;
            white-space: nowrap;
        }
        .pay{
            width: 90%;
            line-height: .88rem;
            border-radius: .08rem;
            color: #fff;
            text-align: center;
            font-size: 14px;
            background: #fa4535;
            position: fixed;
            left: 5%;
            right: 5%;
            bottom: .2rem;
        }
        .icon-false{
            width: .37rem;
            height: .37rem;
            margin-right: .2rem;
            vertical-align: middle;
        }
    </style>
</head>
<body>
<div id="mains_article" style="display: block;">
    <div class="ov pl2 pr2 bff" style="border-bottom: 0.01rem solid #dcdcdc;">
        <div class="fl he88">支付金额</div>
        <div class="fr cred he88" id="price">0.00元</div>
    </div>
    <!--<div class="ov pl2 pr2 bff cou" style="border-bottom: 0.01rem solid #dcdcdc; position: relative;">
        <div class="fl he88">优惠券</div>
        <div class="fr cred he88" >
        	<p class="coupon" style="margin-right: 0.25rem;color:#333;">请选择</p>
        	<img src="../img/下一步@2x.png" style="width: 9px;position: absolute;right: 0;top: .32rem;right: .2rem;">
        </div>
    </div>-->
     <!--<div class="ov pl2 pr2 bff" style="border-bottom: 0.01rem solid #dcdcdc;">
        <div class="fl he88">实际支付金额</div>
        <div class="fr cred he88" id="prices"></div>
    </div>-->
 <!--   <div class="he88 pl2">
        选择支付方式
    </div>
    <div class="he88 pl2">
        其他支付方式
    </div>-->
    <div class="ov pl2  bff" id="wx_pays">
        <div class="fl he88">
            <img src="../img/微信支付%20(1)@2x%202.png" class="rimg vm" >
            <span class="vm c33">微信支付</span>
        </div>
        <div class="fr he88 w50 tr">
            <img src="../img/duisa@2x.png" id="wx_icon" ons="0" class="icon-false">
        </div>
    </div>
    <div class="pay" id="pay" onclick="wxPay()">立即支付</div>
</div>
</body>
<script src="../js/jquery-1.8.3.min.js"></script>
<script src="../js/public.js"></script>
<script>
    var price = parseFloat(GetQueryString("price"));//订单价格
    //var orderNum = GetQueryString("num");//订单
  	//1 代表竞拍的时候买家支付保证金（冻结款），2 代表直接购买，3 代表在待付款中的付款，4代表卖家支付的保证金，5代表众筹，6代表捡漏（未完成）
    var orderType = GetQueryString("orderType");//定金，金额，还是重酬等等,众筹
    var coupon_id = GetQueryString("coupon_id")=="null"?0:GetQueryString("coupon_id");//优惠券的id
    var orderNum = GetQueryString("order_num")==null?GetQueryString("num"):GetQueryString("order_num");//订单编号，只有在待付款中才有这字段
    var auction_id = GetQueryString("auction_id");//产品的id
    var store_id = GetQueryString("storeId");//获取卖家的店铺id，而不是微信登录以后的店铺id。此参数为向商家付款专用参数
    //console.log(GetQueryString("order_num"));
    //console.log(orderNum);
    var appId = "";
    var prepayId = "";
    var timeStamp = "";
    var nonceStr = "";
    var paySign = "";
    var signType = "";
    $("#price").text(price.toFixed(2));
    function wxPay(){ //微信支付
        $.ajax({
            url:base_url+"ZITAOHUI/wexinpay",
            type:"post",
            data:{
                total_fee:parseInt(Math.round(price*100)),//金额
                userId:sessionStorage.getItem("uid"),//userid
                id:orderNum,//订单号
                value:orderType,//订单状态  1 代表竞拍的时候买家支付保证金（冻结款），2 代表直接购买，3 代表在待付款中的付款，4代表卖家支付的保证金，5代表众筹，6代表捡漏（未完成）
                coupon_id:coupon_id,//优惠券id
                auction_id:auction_id,//产品的id
                store_id:store_id
            },
            dataType:"json",
            success:function (data){
                if(data.code == 1){
                    console.log(data);
                    var d = data.extend.data;
                    appId = d.appId;
                    prepayId = d.package;
                    timeStamp = d.timeStamp;
                    nonceStr = d.nonceStr;
                    paySign = d.paySign;
                    signType = d.signType;
                    onBridgeReady();
                }else{
                    alert("请求失败，暂无法支付");
                }
            },
            error:function (data){
              alert("地址失效");
            }
        })
    }
    function onBridgeReady(){
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
                "appId" : appId,//公众号名称，由商户传入
                "timeStamp":timeStamp,//时间戳，自1970年以来的秒数
                "nonceStr" : nonceStr,//随机串
                "package" : prepayId,
                "signType" : signType,//微信签名方式：
                "paySign" : paySign//微信签名
            },
            function(res){
				console.log(res);
                if(res.err_msg == "get_brand_wcpay_request:ok" ) {
                	alert('支付成功');
                    window.location.href = "../index.html";
                    // 使用以上方式判断前端返回,微信团队郑重提示：res.err_msg将在用户支付成功后返回    ok，但并不保证它绝对可靠。
                }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
                	alert('支付失败');
                    //window.location.href = "../index.html";
                }else if(res.err_msg == "get_brand_wcpay_request:fail"){
                	alert('支付失败');
                    //window.location.href = "../index.html";
                }
            }
        );
    }
</script>
</html>